﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SCRUM.Core.BusinessObjects;

namespace SCRUM.Core.DAO
{
    /// <summary>
    /// Data access object for work reports.
    /// </summary>
    public static class DAOWorkProgress
    {
        /// <summary>
        /// Gets the progress for user.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <returns></returns>
        public static IList<WorkProgress> GetProgressForUser(User user)
        {
			return GetProgressForUser(user, new DateTime(1900, 1, 1), DateTime.MaxValue);
        }

		/// <summary>
		/// Gets the progress for user.
		/// </summary>
		/// <param name="user">The user.</param>
		/// <param name="from">From.</param>
		/// <param name="to">To.</param>
		/// <returns></returns>
		public static IList<WorkProgress> GetProgressForUser(User user, DateTime? from, DateTime? to)
		{
			if (!from.HasValue)
			{
				from = new DateTime(1900, 1, 1);
			}
			if (!to.HasValue)
			{
				to = DateTime.MaxValue;
			}
			return DataProviders.ProviderFactory.Provider.GetProgressForUser(user.ID, from.Value, to.Value);
		}

        /// <summary>
        /// Adds the progress.
        /// </summary>
        /// <param name="taskID">The task ID.</param>
        /// <param name="date">The date.</param>
        /// <param name="storyPoints">The story points.</param>
        /// <param name="note">The note.</param>
        public static void AddProgress(int taskID, DateTime date, double storyPoints, string note)
        {
            DataProviders.ProviderFactory.Provider.AddWorkProgress(DAO.DAOUser.GetLoggedUser().ID, taskID, date, storyPoints, note);
        }

        /// <summary>
        /// Adds the progress.
        /// </summary>
        /// <param name="userLogin">The user login.</param>
        /// <param name="taskID">The task ID.</param>
        /// <param name="date">The date.</param>
        /// <param name="storyPoints">The story points.</param>
        /// <param name="note">The note.</param>
        public static void AddProgress(string userLogin, int taskID, DateTime date, double storyPoints, string note)
        {
            User user = DAOUser.GetByLogin(userLogin);
            DataProviders.ProviderFactory.Provider.AddWorkProgress(user.ID, taskID, date, storyPoints, note);
        }

		/// <summary>
		/// Deletes the progress.
		/// </summary>
		/// <param name="progressID">The progress ID.</param>
		public static void DeleteProgress(int progressID)
		{
			DataProviders.ProviderFactory.Provider.DeleteWorkProgress(progressID);			
		}

		/// <summary>
		/// Edits the progress.
		/// </summary>
		/// <param name="workProgress">The work progress.</param>
		public static void EditProgress(WorkProgress workProgress)
		{
			DataProviders.ProviderFactory.Provider.EditWorkProgress(workProgress);
		}

		/// <summary>
		/// Gets the progress by ID.
		/// </summary>
		/// <param name="progressID">The progress ID.</param>
		/// <returns>Work progress with specified ID.</returns>
		public static WorkProgress GetProgressByID(int progressID)
		{
			return DataProviders.ProviderFactory.Provider.GetProgressByID(progressID);
		}
	}
}
